import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
import java.util.Set;
public class inputUrl {
    public String getUrl() throws NoSuchUrlException {
        Scanner input = new Scanner(System.in);

        String url=input.nextLine();
        if (url.length()<10||!(url.substring(0,7).contains("http://"))){throw new NoSuchUrlException();}
        input.close();
        return url;
    }

    public byte[] readUrl(String parsedUrl) throws IOException {

        URL url;
        URLConnection connection;
        InputStream IS;
        ByteArrayOutputStream BAOS;
        FileOutputStream FOS;
        int contentLength=0;

        url=new URL(parsedUrl);
        connection = url.openConnection();
        IS = url.openStream();
        contentLength = connection.getContentLength();
        BAOS = new ByteArrayOutputStream(16384);
        byte[] byteIn = new byte[512];

        while (true) {
            int len = IS.read(byteIn);
            if (len == -1) {break;}
            BAOS.write(byteIn, 0, len);
        }
        IS.close();
        BAOS.close();
        byte[] byteOut = BAOS.toByteArray();
        return byteOut;
    }

    public boolean checkUrl(String url) throws IOException {

        URL urlConnect;
        String type;
        URLConnection connection;

        urlConnect=new URL(url);
        type = url.substring(url.lastIndexOf("."));
        if(type.length()>5||type.contains("?")){return true;}
        connection = urlConnect.openConnection();
        String checkType= type.replace(".","");
        return checkType.equals("");
    }
}
